
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class runFair {
    public static void main(String[] args) throws Exception {
        int startTime = (int)System.currentTimeMillis();
        ReentrantLock locker = new ReentrantLock(true);
        //false时为非公平锁，输出的结果为乱序，true为升序，即非公平锁后面的线程会抢占前面进程的资源。效率较高
        ExecutorService pool = Executors.newFixedThreadPool(3);
            for(int i=0;i<2000;i++){
                try{
                    pool.execute(new MyTask(Integer.toString(i),locker));

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            pool.shutdown();
            pool.awaitTermination(1, TimeUnit.MINUTES);


            int endTime = (int)System.currentTimeMillis();
            System.out.println("总共耗时："+(endTime-startTime)+" 毫秒");

    }
}
